package br.com.vti.leilao.model.entity;

import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import br.com.vti.leilao.model.annotation.Constraint;
import br.com.vti.leilao.model.annotation.Constraints;

/**
 *
 * @author ednardomatos
 */
@Entity
@Table(name = "t_empresa", catalog = "homologacao", schema = "leilao")
@SequenceGenerator(name = "seq_empresa", sequenceName = "leilao.seq_empresa", initialValue = 1, allocationSize = 1)
@Constraints({
		@Constraint(name = "t_empresa_nome_key", message = {"erro.existe.registro", "campo.nome" }),
		@Constraint(name = "t_empresa_dominio_key", message = {"erro.existe.registro", "campo.dominio"}) })
public class Empresa implements Model<Integer> {
    
    private static final long serialVersionUID = -6643326144301758622L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_empresa")
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "nome")
    private String nome;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "dominio")
    private String dominio;
    
    public Empresa() {
    }

    public Empresa(Integer id, String nome, String dominio) {
        this.id = id;
        this.nome = nome;
        this.dominio = dominio;
    }

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getDominio() {
        return dominio;
    }

    public void setDominio(String dominio) {
        this.dominio = dominio;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + (this.nome != null ? this.nome.hashCode() : 0);
        hash = 79 * hash + (this.dominio != null ? this.dominio.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Empresa other = (Empresa) obj;
        if ((this.nome == null) ? (other.getNome() != null) : !this.nome.equals(other.getNome())) {
            return false;
        }
        if ((this.dominio == null) ? (other.getDominio() != null) : !this.dominio.equals(other.getDominio())) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Empresa{" + "nome=" + nome + ", dominio=" + dominio + "}";
    }
    
}
